package models

import (
	"social-app/dao"
	"time"
)

type DynamicPraise struct {
	Id         int       `json:"id"`
	UserId     int       `json:"user_id"`
	DynamicId  int       `json:"dynamic_id"`
	CreateTime time.Time `json:"create_time" gorm:"AutoCreateTime"`
	UpdateTime time.Time `json:"update_time" gorm:"AutoUpdateTime"`
}

func (d *DynamicPraise) TableName() string {
	return "dynamic_praise"
}

func (d *DynamicPraise) Create(user_id int, dynamic_id int) *DynamicPraise {
	dao.Db.Where("user_id = ? and dynamic_id = ?", user_id, dynamic_id).First(&d)
	if d.Id > 0 {
		dao.Db.Where("user_id = ? and dynamic_id = ?", user_id, dynamic_id).Delete(&d)
		d.Id = 0
	} else {
		d.UserId = user_id
		d.DynamicId = dynamic_id
		dao.Db.Create(&d)
	}
	return d
}
